home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dirut / dosdir21.zip / DOSDIR.H < prev    next >
C/C++ Source or Header  |  1994-06-22  |  6KB  |  203 lines

  1.  
  2. /*      dosdir.h
  3.  
  4.     Defines structures, macros, and functions for dealing with
  5.     directories and pathnames.
  6.  
  7.     Copyright (C) 1994 Jason Mathews.
  8.     Permission is granted to any individual or institution to use, copy,
  9.     redistribute or modify this software so long as it is not sold for
  10.     profit, provided this copyright notice is retained.
  11.  
  12.     Modification history:
  13.  
  14.      V1.0  13-May-94, J Mathews    Original version.
  15.      V1.1   8-Jun-94, J Mathews    Added VMS definitions, added dd_
  16.                     prefix to functions/constants.
  17. */
  18.  
  19. #ifndef _DOSDIR_H
  20. #define _DOSDIR_H
  21.  
  22. /* Set up portability */
  23. #include "tailor.h"
  24.  
  25. #if defined (MSDOS)
  26. #    include <dos.h>
  27. #  ifdef __TURBOC__
  28. #    include <dir.h>
  29. #  else /* ?!__TURBOC__ */
  30. #    include <direct.h>
  31. #  endif /* ?TURBOC */
  32. #  define ALL_FILES_MASK "*.*"
  33. #  define DIR_PARENT ".."
  34. #  define DIR_END '\\'
  35. #elif defined(VMS)
  36. #  include <rms.h>
  37. #  define ALL_FILES_MASK "*.*"
  38. #  define DIR_PARENT "[-]"
  39. #  define DIR_END ']'
  40. #else /* ?UNIX */
  41. #  include <memory.h>
  42. #  include <dirent.h>
  43. #  define ALL_FILES_MASK "*"
  44. #  define DIR_PARENT ".."
  45. #  define DIR_END '/'
  46. #endif /* ?__TURBOC__ */
  47.  
  48. /* MS-DOS flags equivalent to "dos.h" file attribute definitions */
  49.  
  50. #define DD_NORMAL   0x00    /* Normal file, no attributes */
  51. #define DD_RDONLY   0x01    /* Read only attribute */
  52. #define DD_HIDDEN   0x02    /* Hidden file */
  53. #define DD_SYSTEM   0x04    /* System file */
  54. #define DD_LABEL    0x08    /* Volume label */
  55. #define DD_DIREC    0x10    /* Directory */
  56. #define DD_ARCH        0x20    /* Archive */
  57. #define DD_DEVICE   0x40    /* Device */
  58.  
  59. #define DD_DOSATTRIBS 0x3f          /* DOS ATTRIBUTE MASK */
  60.  
  61. /*
  62.  *  note that all DOS file attributes defined above do not overlap the
  63.  *  DOS stat definitions, but will conflict will non-DOS machines, so
  64.  *  use following macros to access the flags instead.
  65.  */
  66.  
  67. #define DD_ISNORMAL(m)   ((m) & S_IFREG)
  68. #ifdef MSDOS
  69. #  define DD_ISRDONLY(m) ((m) & DD_RDONLY)
  70. #  define DD_ISHIDDEN(m) ((m) & DD_HIDDEN)
  71. #  define DD_ISSYSTEM(m) ((m) & DD_SYSTEM)
  72. #  define DD_ISLABEL(m)  ((m) & DD_LABEL)
  73. #  define DD_ISDIREC(m)  ((m) & (DD_DIREC | S_IFDIR))
  74. #  define DD_ISARCH(m)   ((m) & DD_ARCH)
  75. #else
  76. #  define DD_ISRDONLY(m) !((m) & S_IWRITE)
  77. #  define DD_ISHIDDEN(m) (0)
  78. #  define DD_ISSYSTEM(m) (0)
  79. #  define DD_ISLABEL(m)  (0)
  80. #  define DD_ISDIREC(m)  ((m) & S_IFDIR)
  81. #  define DD_ISARCH(m)   (0)
  82. #endif /* ?MSDOS */
  83.  
  84. #if (defined(UNIX) || defined(VMS))
  85. #  include <errno.h>
  86. #  ifndef ENOENT
  87. #    define ENOENT -1
  88. #  endif
  89. #  ifndef ENMFILE
  90. #    define ENMFILE ENOENT
  91. #  endif
  92. #endif /* ?UNIX/VMS */
  93.  
  94. /* flags used by fnsplit */
  95.  
  96. #ifndef __TURBOC__
  97. #  define WILDCARDS    0x01
  98. #  define EXTENSION    0x02
  99. #  define FILENAME    0x04
  100. #  define DIRECTORY    0x08
  101. #  define DRIVE        0x10
  102. #endif
  103.  
  104. /* definitions and types corresponding to those in dir.h */
  105.  
  106. #include <time.h> /* for time_t definition */
  107.  
  108. #if defined (MSDOS)
  109. #  define DD_MAXDRIVE    3
  110. #  ifndef __FLAT__
  111. #    define DD_MAXPATH    80
  112. #    define DD_MAXDIR    66
  113. #    define DD_MAXFILE  16
  114. #    define DD_MAXEXT   10 /* allow for wildcards .[ch]*, .etc */
  115. #  else
  116. #    define DD_MAXPATH    260
  117. #    define DD_MAXDIR    256
  118. #    define DD_MAXFILE    256
  119. #    define DD_MAXEXT    256
  120. #  endif /* ?__FLAT__ */
  121.    typedef long    off_t;
  122. #  ifdef __TURBOC__
  123.      typedef short   mode_t;
  124. #  else /* ?!__TURBOC__ */
  125.      typedef unsigned short   mode_t;
  126. #  endif /* ?__TURBOC__ */
  127. #elif defined(VMS)
  128. #  define DD_MAXPATH    NAM$C_MAXRSS
  129. #  define DD_MAXDRIVE    1
  130. #  define DD_MAXDIR    NAM$C_MAXRSS
  131. #  define DD_MAXFILE    80
  132. #  define DD_MAXEXT    32
  133. typedef unsigned short mode_t;
  134. #else /* ?unix */
  135. /*
  136.  * DD_MAXPATH defines the longest permissable path length,
  137.  * including the terminating null. It should be set high
  138.  * enough to allow all legitimate uses, but halt infinite loops
  139.  * reasonably quickly.
  140.  */
  141. #  define DD_MAXPATH    1024
  142. #  define DD_MAXDRIVE    1
  143. #  define DD_MAXDIR    768
  144. #  define DD_MAXFILE    255
  145. #  define DD_MAXEXT    1
  146.    typedef struct dirent DIR_ENT;
  147. #endif /* ?MSDOS */
  148.  
  149. typedef struct {
  150.     char*  dd_name;             /* File name */
  151.     time_t dd_time;             /* File time stamp */
  152.     off_t  dd_size;             /* File length */
  153.     mode_t dd_mode;             /* Attributes of file */
  154.  
  155.     /*  Below is private (machine specific) data, which should
  156.      *  only be accessed by dosdir modules.
  157.      */
  158. #if defined (MSDOS)
  159. #  ifdef __TURBOC__
  160.     struct ffblk  dos_fb;
  161. #  else /* ?MSC */
  162.     struct find_t dos_fb;
  163. #  endif /* ?TURBOC */
  164. #elif defined (VMS)
  165.     struct FAB  fab;
  166.     struct NAM  nam;
  167.     char        rms_filespec[DD_MAXPATH];
  168.     char        esa[DD_MAXPATH];
  169.     char        rsa[DD_MAXPATH];
  170.     char        path[DD_MAXPATH];
  171.     char*       filespec;
  172.     char        dd_attribs;
  173. #else /* ?unix */
  174.     DIR*          dd_dirp;                /* Directory ptr */
  175.     DIR_ENT*      dd_dp;                  /* Directory entry */
  176.     char          dd_attribs;             /* File search attributes */
  177.     char          dd_filespec[DD_MAXFILE];   /* File search mask */
  178. #endif /* ?MSDOS */
  179. }   dd_ffblk;
  180.  
  181.  
  182. #ifdef __cplusplus
  183. extern "C" {
  184. #endif
  185.  
  186. int  dd_findfirst  OF((const char *path, dd_ffblk *fb, int attrib));
  187. int  dd_findnext   OF((dd_ffblk *fb));
  188. int  dd_fnsplit    OF((const char *path, char * drive, char * dir,
  189.             char * name, char * ext));
  190.  
  191. #ifndef __TURBOC__
  192. int  getdisk    OF((void));
  193. int  setdisk    OF((int drive));
  194. #endif /* ?!__TURBOC__ */
  195.  
  196. #ifdef __cplusplus
  197. }
  198. #endif
  199.  
  200. extern struct stat dd_sstat;
  201.  
  202. #endif /* _DOSDIR_H */
  203.